#pragma once

#include "SynTable.h"

SynTable::SynTable()
{
	indexCount=0;
	synIndex = map<std::string, SynTableEntry>();
	revIndex = map<int, SynTableEntry>();
}

int SynTable::getNoOfEntries()
{
	return synIndex.size();
}

SynTableEntry SynTable::getAt(int index)
{
	return revIndex.at(index);
}

SynTableEntry SynTable::getByName(string synName)
{
	return synIndex.find(synName)->second;
}

bool SynTable::addSyn(Synonym* synonym, vector<int> values)
{
	int index;

	map<std::string, SynTableEntry>::iterator entryIt;
	if((entryIt = synIndex.find(synonym->getVariable())) != synIndex.end())
	{
		index = entryIt->second.getEntryNo();
		entryIt->second.checkValues(values);
		return revIndex.at(index).checkValues(values);
	}
	else
	{
		index = indexCount;
		SynTableEntry entry(synonym, indexCount++);
		entry.addValues(values);
		synIndex.insert(make_pair(synonym->getVariable(),entry));
		revIndex.insert(make_pair(index,entry));
		return true;
	}
}

vector<int> SynTable::getResults(Synonym toSearch)
{
	map<std::string, SynTableEntry>::iterator entryIt;
	entryIt = synIndex.find(toSearch.getVariable());

	if(entryIt != synIndex.end())
		return entryIt->second.getValues();
	else
	{
		vector<int> notInTable;
		return notInTable;
	}
}